﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Tools : MonoBehaviour
{
    public static T LoadPrefab<T>(string path) where T : Object
    {
        if (string.IsNullOrEmpty(path)) return null;

        T go = Resources.Load(path) as T;
        if (go == null)
        {
            Debug.LogError("Can't find the prefab!");
            return null;
        }

        return go;
    }

    public static GameObject InstantiatePrefab(string path, Transform parent, Vector2 localPos = default(Vector2))
    {
        GameObject go = LoadPrefab<GameObject>(path);
        if (go == null) return null;
        go = Instantiate(go);
        go.transform.SetParent(parent);
        go.transform.localScale = Vector3.one;
        go.transform.localRotation = Quaternion.identity;
        go.GetComponent<RectTransform>().anchoredPosition = localPos;
        return go;
    }
}
